package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.SystemUserEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 系统用户表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class SystemUserProvider {

    /**
     * 增加SystemUser
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertSystemUser(@Param("entity") SystemUserEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" system_user ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" login_username ", " #{entity.loginUsername,jdbcType=VARCHAR} ");
                VALUES(" login_password ", " #{entity.loginPassword,jdbcType=VARCHAR} ");
                VALUES(" login_secret_key ", " #{entity.loginSecretKey,jdbcType=VARCHAR} ");
                VALUES(" job_no ", " #{entity.jobNo,jdbcType=VARCHAR} ");
                VALUES(" full_name ", " #{entity.fullName,jdbcType=VARCHAR} ");
                VALUES(" user_gender_code ", " #{entity.userGenderCode,jdbcType=SMALLINT} ");
                VALUES(" mobile_phone ", " #{entity.mobilePhone,jdbcType=VARCHAR} ");
                VALUES(" other_phone ", " #{entity.otherPhone,jdbcType=VARCHAR} ");
                VALUES(" address ", " #{entity.address,jdbcType=VARCHAR} ");
                VALUES(" company_id ", " #{entity.companyId,jdbcType=INTEGER} ");
                VALUES(" department_id ", " #{entity.departmentId,jdbcType=INTEGER} ");

                if (entity.getDisableState() != null) {
                    VALUES(" disable_state ", " #{entity.disableState,jdbcType=TINYINT} ");
                }


                if (entity.getAsLogin() != null) {
                    VALUES(" as_login ", " #{entity.asLogin,jdbcType=TINYINT} ");
                }

                VALUES(" ic_card_code ", " #{entity.icCardCode,jdbcType=VARCHAR} ");
                VALUES(" sort ", " #{entity.sort,jdbcType=INTEGER} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改SystemUser
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateSystemUser(@Param("entity") SystemUserEntity entity) {
        return new SQL() {
            {
                UPDATE(" system_user ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" login_username = #{entity.loginUsername,jdbcType=VARCHAR} ");
                SET(" login_password = #{entity.loginPassword,jdbcType=VARCHAR} ");
                SET(" login_secret_key = #{entity.loginSecretKey,jdbcType=VARCHAR} ");
                SET(" job_no = #{entity.jobNo,jdbcType=VARCHAR} ");
                SET(" full_name = #{entity.fullName,jdbcType=VARCHAR} ");
                SET(" user_gender_code = #{entity.userGenderCode,jdbcType=SMALLINT} ");
                SET(" mobile_phone = #{entity.mobilePhone,jdbcType=VARCHAR} ");
                SET(" other_phone = #{entity.otherPhone,jdbcType=VARCHAR} ");
                SET(" address = #{entity.address,jdbcType=VARCHAR} ");
                SET(" company_id = #{entity.companyId,jdbcType=INTEGER} ");
                SET(" department_id = #{entity.departmentId,jdbcType=INTEGER} ");

                if (entity.getDisableState() != null) {
                    SET(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }


                if (entity.getAsLogin() != null) {
                    SET(" as_login = #{entity.asLogin,jdbcType=TINYINT} ");
                }

                SET(" ic_card_code = #{entity.icCardCode,jdbcType=VARCHAR} ");
                SET(" sort = #{entity.sort,jdbcType=INTEGER} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询SystemUser列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listSystemUser(@Param("entity") SystemUserEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,login_username,login_password,login_secret_key,job_no,full_name,user_gender_code,mobile_phone,other_phone,address,company_id,department_id,disable_state,as_login,ic_card_code,sort,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" system_user ");

                if (entity.getLoginUsername() != null) {
                    WHERE(" login_username = #{entity.loginUsername,jdbcType=VARCHAR} ");
                }

                if (entity.getLoginPassword() != null) {
                    WHERE(" login_password = #{entity.loginPassword,jdbcType=VARCHAR} ");
                }

                if (entity.getLoginSecretKey() != null) {
                    WHERE(" login_secret_key = #{entity.loginSecretKey,jdbcType=VARCHAR} ");
                }

                if (entity.getJobNo() != null) {
                    WHERE(" job_no = #{entity.jobNo,jdbcType=VARCHAR} ");
                }

                if (entity.getFullName() != null) {
                    WHERE(" full_name = #{entity.fullName,jdbcType=VARCHAR} ");
                }

                if (entity.getUserGenderCode() != null) {
                    WHERE(" user_gender_code = #{entity.userGenderCode,jdbcType=SMALLINT} ");
                }

                if (entity.getMobilePhone() != null) {
                    WHERE(" mobile_phone = #{entity.mobilePhone,jdbcType=VARCHAR} ");
                }

                if (entity.getOtherPhone() != null) {
                    WHERE(" other_phone = #{entity.otherPhone,jdbcType=VARCHAR} ");
                }

                if (entity.getAddress() != null) {
                    WHERE(" address = #{entity.address,jdbcType=VARCHAR} ");
                }

                if (entity.getCompanyId() != null) {
                    WHERE(" company_id = #{entity.companyId,jdbcType=INTEGER} ");
                }

                if (entity.getDepartmentId() != null) {
                    WHERE(" department_id = #{entity.departmentId,jdbcType=INTEGER} ");
                }

                if (entity.getDisableState() != null) {
                    WHERE(" disable_state = #{entity.disableState,jdbcType=TINYINT} ");
                }

                if (entity.getAsLogin() != null) {
                    WHERE(" as_login = #{entity.asLogin,jdbcType=TINYINT} ");
                }

                if (entity.getIcCardCode() != null) {
                    WHERE(" ic_card_code = #{entity.icCardCode,jdbcType=VARCHAR} ");
                }

                if (entity.getSort() != null) {
                    WHERE(" sort = #{entity.sort,jdbcType=INTEGER} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}